#include "head.h"

int net_rm(request_t *request, int net_fd) {
    
    char rm[10] = "rm ";
    char full_path[1024] = {0};
    getcwd(full_path, sizeof(full_path));
    strcat(full_path, "/");
    strcat(full_path, request->user_name);
    strcat(full_path, "/");
    strcat(full_path, request->path);
    strcat(full_path, "/");
    strcat(full_path, request->args);
    printf("%s\n",full_path);

    strcat(rm, full_path);
    // // 1. 读取文件名
    // char *path = request->path;
    // char *filename = request->args;
    // // 拼接rm命令和路径
    // char *rm_cmd;
    // strcpy(rm_cmd, "rm ");
    // strcat(rm_cmd, path);
    // strcat(rm_cmd, filename);
    // 执行rm命令
    int ret = system(rm);

    // 发送响应
    response_t response;
    if (ret != 0) {
        response.status = 1;
        strcpy(response.args, "delete file failed");
        // printf("%s\n", response.args);
        send(net_fd, &response, sizeof(response_t), 0);
        return 0;
    }
    response.status = 0;
    strcpy(response.args, "delete file success");
    // printf("%s\n", response.args);
    send(net_fd, &response, sizeof(response_t), 0);
    return 0;
}

// 测试
// int main(void) {
//     request_t request;

//     strcpy(request.path, "/home/anmoxuan/code/disk-project/server/");
//     strcpy(request.args, "test.txt");
//     net_rm(&request);
//     return 0;
// }